'use strict';

/**
 * 注册
 */
angular.module('app').controller('registerCtrl',['$interval','$http','$scope','$state',function ($interval,$http,$scope,$state) {
    /**
     * 表单提交 注册
     *
     * 表单接收的值：console.log($scope.user);
     */
    $scope.submit = function () {
        $http.post('data/regist.json',$scope.user).success(function (resp) {
            $state.go('login');
        });
    };

    /**
     * 发送短信
     * $interval.cancel(interval);取消掉
     *
     */
    var count = 60;
    $scope.send = function () {
        $http.get('data/code.json').success(function (resp) {
            if(resp.state === 1){
                count = 60;
                $scope.time = '60s';
                var interval = $interval(function () {
                    if(count <= 0){
                        $interval.cancel(interval);
                        $scope.time = '';
                    }else{
                        count--;
                        $scope.time = count + 's';
                    }
                },1000);
            }
        });
    }
}]);




